<#include "../../select.ftl" />
<!-- Modal -->
<div class="modal-dialog wide" style="width: 1000px;">
<div class="modal-content">
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">
    <#if ykOrder??>
        <#if ykOrder.id??>
            编辑
        <#else>
            新增
        </#if>
    </#if>
    </h4>
</div>
<div class="modal-body">
<div id="errorMessage"><#include "../../message.ftl" /></div>
<form class="form-horizontal" role="form" id="ykOrderForm" method="post"
      action="${absoluteContextPath}/yk/ykOrder/save">
<#if ykOrder??>
    <#if ykOrder.id??>
    <input type="hidden" name="id" value="${ykOrder.id?c}"/>
    <#else>
    <input type="hidden" name="id" value=""/>
    </#if>
</#if>
<div class="table-responsive" id="ykOrderContent">
<#include "order.ftl"/>
</div>
<div class="table-responsive" id="ykTypeContent">
<#include "yktype.ftl"/>
</div>

<div class="row">

<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">下单日期</label>

    <div class="col-sm-8">
        <input name="billTime" value="${ykOrder.billTime!''}" type="text" class="form-control"/>
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">开卡日期</label>

    <div class="col-sm-8">
        <input name="billStart" id="billStart" value="${ykOrder.billStart!''}" type="text" class="form-control"
               onblur=funTime(this.value)/>
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">到期日期</label>

    <div class="col-sm-8">
        <input name="billEnd" id="billEnd" value="${ykOrder.billEnd!''}" type="text" class="form-control"/>
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">渠道类型</label>

    <div class="col-sm-8">
    <@select name="channelType" value="${ykOrder.channelType!''}" list=channelTypeList class="form-control"/>
                            <#--<input name="channelType" value="${ykOrder.channelType!''}" type="text" class="form-control"/>-->
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">渠道来源</label>

    <div class="col-sm-8">
    <@select name="spareC" value="${ykOrder.spareC!''}" list=vipqdTypeList class="form-control"/>

    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">引荐人</label>

    <div class="col-sm-8">

        <div class="input-group">
        <#if yjName??>
            <input name="yjName" value="${yjName}" type="text"
                   class="form-control" readonly="true"/>
        <#else>
            <input name="yjName" value="${ykOrder.yjName!''}" type="text"
                   class="form-control" readonly="true"/>
        </#if>
            <input name="yjId" value="${ykOrder.yjId!''}"
                   type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctHealthYj(this);"><i
                                        class="fa fa-search"></i></span>
        </div>






    <#--         <input name="yjId" value="${ykOrder.yjId!''}" type="text" class="form-control"/>
             <input name="yjName" value="${ykOrder.yjName!''}" type="text" class="form-control"/>
     -->    </div>
</div>

<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">促会人</label>

    <div class="col-sm-8">
        <div class="input-group">
        <#if chName??>
            <input name="chName" value="${chName}" type="text"
                   class="form-control" readonly="true"/>
        <#else>
            <input name="chName" value="${ykOrder.chName!''}" type="text"
                   class="form-control" readonly="true"/>
        </#if>
            <input name="chId" value="${ykOrder.chId!''}"
                   type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctIllIndex(this);"><i
                                        class="fa fa-search"></i></span>
        </div>



    <#--      <input name="chId" value="${ykOrder.chId!''}" type="text" class="form-control"/>
          <input name="chName" value="${ykOrder.chName!''}" type="text" class="form-control"/>
    -->
    </div>
</div>

<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">分管人</label>

    <div class="col-sm-8">

        <div class="input-group">
            <input name="fgName" value="${ykOrder.fgName!''}" type="text"
                   class="form-control"
                   readonly="true"/>
            <input name="fgId" id="fgId" value="${ykOrder.fgId!''}"
                   type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctReferralsUser(this);"><i
                                        class="fa fa-search"></i></span>
        </div>
    <#-- <input name="fgId" value="${ykOrder.fgId!''}" type="text" class="form-control"/>
     <input name="fgName" value="${ykOrder.fgName!''}" type="text" class="form-control"/>
--> </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">介绍人</label>

    <div class="col-sm-8">
        <input name="spareD" value="${ykOrder.spareD!''}" type="text" class="form-control"/>
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">副会</label>

    <div class="col-sm-8">
        <input name="vipFh" value="${ykOrder.vipFh!''}" type="text" class="form-control"/>
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">是否退会</label>

    <div class="col-sm-8">

    <@select name="vipBack" value="${ykOrder.vipBack!''}" list=vipBackTypeList class="form-control"/>
                        <#--<input name="vipBack" value="${ykOrder.vipBack!''}" type="text" class="form-control"/>-->
    </div>
</div>
<#--<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">收款方式</label>
    <div class="col-sm-8">
        <input name="gatherType" value="${ykOrder.gatherType!''}" type="text" class="form-control"/>
    </div>
</div>
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">收款金额</label>
    <div class="col-sm-8">
        <input name="gatherMoney" value="${ykOrder.gatherMoney!''}" type="text" class="form-control"/>
    </div>
</div>-->
<div class="form-group col-md-4">
    <label class="col-sm-4 control-label">卡数</label>

    <div class="col-sm-8">
        <input name="note" value="${ykOrder.note!''}" type="text" class="form-control"/>
    </div>
</div>
<#--   <div class="form-group col-md-4">
       <label class="col-sm-4 control-label">----</label>
       <div class="col-sm-8">
           <input name="finishStart" value="${ykOrder.finishStart!''}" type="text" class="form-control"/>
       </div>
   </div>
   <div class="form-group col-md-4">
       <label class="col-sm-4 control-label">----</label>
       <div class="col-sm-8">
           <input name="finishEnd" value="${ykOrder.finishEnd!''}" type="text" class="form-control"/>
       </div>
   </div>
   <div class="form-group col-md-4">
       <label class="col-sm-4 control-label">创建人</label>
       <div class="col-sm-8">
           <input name="createUser" value="${ykOrder.createUser!''}" type="text" class="form-control"/>
       </div>
   </div>
   <div class="form-group col-md-4">
       <label class="col-sm-4 control-label">创建时间</label>
       <div class="col-sm-8">
           <input name="createTime" value="${ykOrder.createTime!''}" type="text" class="form-control"/>
       </div>
   </div>-->

<!--
                <div class="form-group col-md-4">
                    <label class="col-sm-4 control-label"></label>
                    <div class="col-sm-8">
                        <input name="spareC" value="${ykOrder.spareC!''}" type="text" class="form-control"/>
                    </div>
                </div>
                <div class="form-group col-md-4">
                    <label class="col-sm-4 control-label"></label>
                    <div class="col-sm-8">
                        <input name="spareD" value="${ykOrder.spareD!''}" type="text" class="form-control"/>
                    </div>
                </div>
                <div class="form-group col-md-4">
                    <label class="col-sm-4 control-label"></label>
                    <div class="col-sm-8">
                        <input name="spareE" value="${ykOrder.spareE!''}" type="text" class="form-control"/>
                    </div>
                </div>
                <div class="form-group col-md-4">
                    <label class="col-sm-4 control-label"></label>
                    <div class="col-sm-8">
                        <input name="spareF" value="${ykOrder.spareF!''}" type="text" class="form-control"/>
                    </div>
                </div>
                <div class="form-group col-md-4">
                    <label class="col-sm-4 control-label"></label>
                    <div class="col-sm-8">
                        <input name="spareG" value="${ykOrder.spareG!''}" type="text" class="form-control"/>
                    </div>
                </div>-->
</div>

<div class="row">
    <div class="tile-header">
        <h1>
            <button type="button" class="btn btn-green" onclick="doAddykGather();"><i
                    class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>
        </h1>
    </div>
    <div class="tile-body nopadding">
        <div class="table-responsive" id="ykGatherContent">
            <table class="table table-datatable table-gray" id="tab">
                <thead>
                <tr>
                    <th style="display:none;">ID</th>
                    <th>收款方式</th>
                    <th>收款金额</th>
                    <th style="width: 10%">操作</th>
                </tr>
                </thead>
                <tbody>
                <#if ykGatherList??>
                    <#list ykGatherList as ykGather>
                    <tr id="${ykGather.id!''}" align="center">

                        <td style="display:none;"><input name="ids" value="${ykGather.id?c!''}"
                                                         type="text" class="form-control"/></td>
                        <td><input name="gatherType" value="${ykGather.gatherType!''}" type="text"
                                   class="form-control"/></td>
                        <td><input name="gatherMoney" value="${ykGather.gatherMoney!''}" type="text"
                                   class="form-control"/></td>

                        <#if (ykGather.id>0)>
                            <td><a class="btn btn-orange btn-radio  nopadding"
                                   onclick="deleteEditykGather(${ykGather.id!''});" title="删除"> <i
                                    class="fa fa-trash-o"></i> </a></td>
                        <#else >
                            <td><a class="btn btn-orange btn-radio  nopadding"
                                   onclick="deleteAddRemove(${ykGather.id!''});" title="删除"> <i
                                    class="fa fa-trash-o"></i> </a></td>
                        </#if>
                    </tr>

                    </#list>
                </#if>

                </tbody>
            </table>
        </div>
    </div>
</div>
</form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
    <button type="button" class="btn btn-primary" onclick="save();">保存</button>
</div>
</div>
</div>
<script>
    function save() {
        $("#" + "ykOrderForm").ajaxSubmit({
            success: function (data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId: "showMessage", message: "信息保存成功！", type: "success"});
                    refreshTable();
                } else {
                    $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：" + data.returnMsg, type: "error"});
                }
            }
        });
    }

    function funChoose(staffId) {
alert("s");
        var data = {};
        var url = '${absoluteContextPath}/yk/ykOrder';
        if (staffId != '') {
            data.staffId = staffId;
            url = url + "/goFind";
        }
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
//
                    $('#ykOrderContent').html(data.content.data);
                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            }
        });
    }


    function funGoYkType(id) {

        var data = {};
        var url = '${absoluteContextPath}/yk/ykOrder/goYkType';
        data.id = id;
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
//
                    $('#ykTypeContent').html(data.content.data);
                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            }
        });
    }


    function funMoney() {

        if ($("input[id='money']").val() != '' && $("#costType").val() != '' && $("input[id='costMoney']").val() != '') {
            if ($("#costType").val() == '1') {
                $("#ykOrderForm input[id='cost']").val($("input[id='costMoney']").val());
            }
            if ($("#costType").val() == '2') {
                $("#ykOrderForm input[id='cost']").val($("input[id='costMoney']").val() * $("input[id='money']").val());
            }
        }
        else {
            $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：" + "金额或成本类型或成本金额比例不能为空", type: "error"});
        }
    }
    function blurOnclick(billStart, vipCycle) {
        var data = {};
        var url = '${absoluteContextPath}/yk/ykOrder';
        if (billStart != '' && vipCycle != '') {
            data.billStart = billStart;
            data.vipCycle = vipCycle;
            url = url + "/goBlur";
        }
        var sdf = "yyyy-MM-dd"
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
//                   console.info(data);
                    if (data.content.billEnd != null) {
                        var date2 = new Date(data.content.billEnd);
                        var endTime = date2.format(sdf);
                        $("#ykOrderForm input[name='billEnd']").val(endTime);
                    }

                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            }
        });
    }


    $(function () {
        $("input[name=billTime]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});

        })

        $("input[name=billStart]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        })
        $("input[name=billStart]").blur(function () {
            if ($(this).val() != '') {
                blurOnclick($(this).val(), $("input[id='vipCycle']").val());
            }
        })
        $("input[name=billEnd]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        })

        $("div[class='tooltip fade top in']").hide();
    });
    var rowCount = 0;
    function doAddykGather() {

        rowCount++;
        $("#tab").append("<tr id='option" + rowCount + "' align='center'>"
                + "<td style='display:none;'><input name='ids' value='' type='text' class='form-control' /></td>"
                + "<td><input name='gatherType' value='' type='text' class='form-control' /></td>"
                + "<td><input name='gatherMoney' value='' type='text'  class='form-control'/></td>"

                + "<td><a class='btn btn-orange btn-radio  nopadding' onclick='deleteAddjjbmx(" + rowCount + ");' title='删除'> <i class='fa fa-trash-o'></i> </a></td>"
                + "</tr>");
    }

    function deleteEditykGather(id) {
        if (id != undefined) {
            $.confirm({
                confirm: function () {
                    $("#confirmModal").modal("hide");
                    $.post("${absoluteContextPath}/yk/ykGather/deletes", {
                        'id': id
                    }, function (data) {
                        data = JSON.parse(data);
                        if (data.returnCode == 1) {
                            $.showMessage({parentId: "errorMessage", message: "收款方式删除成功！", type: "success"});
                            $("#" + id + "").remove();
                        } else {
                            $.showMessage({parentId: "errorMessage", message: "收款方式删除异常！", type: "error"});
                        }
                    });
                }
            });
        }
    }

    function deleteAddjjbmx(rowCount) {
        $("#option" + rowCount + "").remove();
    }
    function deleteAddRemove(id) {
        $("#" + id + "").remove();
    }
</script>